package com.yidu.t299.dao.chr;

import com.yidu.t299.domain.chr.Grades;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface GradesMapper {
    @Select(" SELECT sm.student_id,sm.student_name,c.class_name,c.class_type,l.lesson_name\n" +
            "            FROM grade g \n" +
            "            JOIN lesson l \n" +
            "            ON l.lesson_id = g.lesson_id\n" +
            "            JOIN student_manage sm \n" +
            "            ON g.student_id = sm.student_id\n" +
            "            JOIN class c\n" +
            "            ON c.class_id=sm.class_id" +
            " where 1=1 ${condition} group by g.student_id limit #{page},#{rows}")
    @Results({
            @Result(id = true,column = "student_id", property = "studentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "student_name", property = "studentName", jdbcType = JdbcType.INTEGER),
            @Result(column = "class_type",property = "classType"),
            @Result(column = "class_name",property = "className"),
            @Result(column = "lesson_name",property = "lessonName")
    })
    List<Grades> selectBylesson(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    @Select("select lesson_grade from grade g join student_manage sm on sm.student_id = g.student_id join lesson l on l.lesson_id = g.lesson_id where sm.student_id=#{studentId} and l.lesson_id=#{lessonId} ")
    int selectByStudentName(Integer studentId,Integer lessonId);

    @Select("SELECT count(*) " +
            " FROM grade g" +
            " JOIN lesson l" +
            " ON g.lesson_id=l.lesson_id" +
            " JOIN student_manage sm" +
            " ON g.student_id=sm.student_id" +
            " JOIN class c" +
            " ON sm.class_id=c.class_id" +
            " JOIN school s" +
            " ON sm.school_id=s.school_id" +
            " where 1=1 ${condition}")
    int selectCount(@Param("condition")String condition);

    @Select("select sum(lesson_grade) from grade where student_id=#{studentId}")
    int selectSumlesson(Integer studentId);
}
